$(function () {
    $(".gxmx").hide();
    $("#gxwlmx").hide();
    $("#gxwlmx1").hide();

    $("#gx").bootstrapTable({
        method: "post",
        contentType: 'application/json',
        url: "/gxwl/gxwlsh",
        striped: true,
        pageNumber: 1,
        pagination: true,
        sidePagination: 'server',
        pageSize: 3,
        pageList: [2, 3, 5, 6],
        queryParams: function (parmes) {
            return {
                pageNum: (parmes.offset / parmes.limit) + 1,
                pageSize: parmes.limit,
            }
        },
        columns: [
            {title: "工序设计单号", field: "designId", align: 'center'},
            {title: "产品编号", field: "productId", align: 'center'},
            {title: "产品名称", field: "productName", align: 'center'},
            {title: "设计人", field: "designer", align: 'center'},
            {title: "登记人", field: "register", align: 'center'},
            {title: "登记时间", field: "registerTime", align: 'center'},
            {title: "工时总成本", field: "costPriceSum", align: 'center'},
            {title: "物料总成本", field: "moduleCostPriceSum", align: 'center'},
            {title: "审核", field: "id", align: 'center',
                formatter: function (value, row, index) {
                    let a="<a href='#' onclick='shhe("+JSON.stringify(row)+")'>审核</a>"
                    return a;
                }
            },
        ]
    })
})
let id="";
function shhe(a) {
    id=a.id;
    $("#zhudiv").hide();
    $(".gxmx").show();


    $("#name").html(a.productName);
    $("#bh").html(a.productId);
    $("[name=designer]").html(a.designer);
    $("#djtime").html(a.registerTime);
    $("#comment").html(a.procedureDescribe);
    $("#gxdbh").html(a.designId);
    $("#zcb").html(a.costPriceSum);
    $("#wlcb").html(a.moduleCostPriceSum);
    $("#djr").html(a.register);


    $.ajax({
        method: "post",
        contentType: 'application/json',
        url: "/gxwl/gxmxwlsj/"+a.id,
        dataType:"json",
        async:true,
        success:function (data) {
            let tab=document.getElementById("wlsjmx");
            tab.innerHTML="";
            for (let i=0;i<data.length;i++){
                tab.innerHTML+="<tr><td>"+data[i].detailsNumber+"</td><td>"+data[i].procedureName+"</td><td  class='gxbh1'>"+data[i].procedureId+"</td>" +
                    "<td>"+data[i].labourHourAmount+"</td><td>"+data[i].subtotal+"</td><td class='wlxj'>"+data[i].moduleSubtotal+"</td>" +
                    "<td><a href='#' onclick='shenghe("+data[i].id+")'>查看明细</a></td></tr>"
            }
        }
    })
}

function shenghe(a) {
    $("#gxwlmx").show();
    $(".gxmx").hide();
    $("#gxwlmx1").show();

    $.ajax({
        method: "post",
        contentType: 'application/json',
        url: "/gxwl/gxwlmx/"+a,
        dataType:"json",
        async:true,
        success:function (data) {
            $("#sjdbh").html(data.procedureId);
            $("#gxmc").html(data.procedureName);
            $("#djr").html(data.register);
            $("#djtime").html(data.registerTime);
        }
    })

    $.ajax({
        method: "post",
        contentType: 'application/json',
        url: "/gxwl/scwlmx/"+a,
        dataType:"json",
        async:true,
        success:function (data) {
            let tab2=document.getElementById("gxwlmx2");
            tab2.innerHTML="";
            for (let i=0;i<data.length;i++){
                tab2.innerHTML+="<tr><td class='adxh'>"+data[i].detailsNumber+"</td><td class='adname'>"+data[i].productName+"</td><td class='adbh'>"+data[i].productId+"</td>" +
                    "<td class='adsl'>"+data[i].amount+"</td><td class='addw'>"+data[i].amountUnit+"</td>" +
                    "<td class='addj'>"+data[i].costPrice+"</td><td class='adxj'>"+data[i].subtotal+"</td></tr>"
            }
        }
    })
}

function queding() {
    $("#gxwlmx").hide();
    $("#gxwlmx1").hide();
    $(".gxmx").show();
}

//返回审核列表
function fanhuishen(){
    $("#gxwlmx").hide();
    $("#gxwlmx1").hide();
    $(".gxmx").hide();
    $("#zhudiv").show();
}

function tongguo() {

    if (confirm("确定通过吗？")){
        $.ajax({
            method: "put",
            contentType: 'application/json',
            url: "/gxwl/gxwltg/"+id,
            async:true,
            success:function (data) {
                parent.document.getElementById('iframeId').contentWindow.location.reload(true)
            }
        })
    }

}

function butongguo() {
    if (confirm("确定不通过吗？")){
        $.ajax({
            method: "put",
            contentType: 'application/json',
            url: "/gxwl/gxwlbtg/"+id,
            async:true,
            success:function (data) {
                parent.document.getElementById('iframeId').contentWindow.location.reload(true);
            }
        })
    }

}